package com.software.project_view.controller;

import com.alibaba.fastjson.JSON;
import com.software.project_view.entity.SubmitItem;
import com.software.project_view.service.impl.BlockServiceImpl;
import com.software.project_view.service.impl.SubmitItemServiceImpl;
import com.software.project_view.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/block")
@CrossOrigin
@RestController
public class BlockController {

    @Autowired
    private BlockServiceImpl blockService;

    @Autowired
    private SubmitItemServiceImpl submitItemService;

    @GetMapping("/genesisBlock")
    public String genesisBlock() {
        R r = blockService.genesisBlock();
        return JSON.toJSONString(r);
    }

    @GetMapping("/getRecentBlock")
    public String getRecentBlock() {
        R recentBlock = blockService.getRecentBlock();
        return JSON.toJSONString(recentBlock);
    }

    @PostMapping("/submit")
    public String submit(@RequestBody SubmitItem submitItem) {
        R r = submitItemService.submit(submitItem);
        return JSON.toJSONString(r);
    }

    @GetMapping("/getAllBlock")
    public String getAllBlock() {
        R blockAll = blockService.getBlockAll();
        return JSON.toJSONString(blockAll);
    }
}
